package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Discountype;
import com.restaurant.service.DiscountypeService;

public class DiscountypeServiceImpl implements DiscountypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountype addOrModify( Discountype objDiscountype ) {
       return ( Discountype ) hibernateTemplate.merge( objDiscountype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountype deleteRecord( Discountype objDiscountype ) {
       hibernateTemplate.delete( objDiscountype );
       return objDiscountype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountype modifyRecord( Discountype objDiscountype ) {
       return ( Discountype ) hibernateTemplate.merge( objDiscountype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Discountype> loadAll() {
       return (List<Discountype>)hibernateTemplate.findByNamedQuery( "Discountype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountype loadByPrimaryKey( Long primaryKey ) {
       return (Discountype) hibernateTemplate.get( Discountype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Discountype> loadByHql(String query) {
       return ( List<Discountype> ) hibernateTemplate.find( query );
   }
}